package com.miao.edu.authority.remote;

import com.miao.edu.authority.service.AuthService;
import com.miao.edu.authority.dto.JwtDto;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author niemiao
 */
public class OauthRemoteServiceImpl implements OauthRemoteService {

    @Autowired
    private AuthService authService;

    @Override
    public JwtDto getJwt(String authentication) {
        Jws<Claims> jwt = authService.getJwt(authentication);
        JwtDto jwtDto = new JwtDto();
        if (jwt != null && jwt.getBody() !=null) {
            jwtDto.setUsername((String)jwt.getBody().get("user_id"));
            jwtDto.setUsername((String)jwt.getBody().get("user_name"));
            return jwtDto;
        }
        return null;
    }

    @Override
    public boolean ignoreAuthentication(String url) {

        return false;
    }

}
